<template>
  <div ref="histogramBar" id="histogramBar" style="width: 100%; height: 100%"></div>
</template>
<script lang="ts">
import { defineComponent, onMounted, ref } from "vue";
import * as echarts from "echarts";
import { debounce } from "./mixins/debounce";
export default defineComponent({
  setup(props: any) {
    // echart节点
    const charts = ref<HTMLElement | null>(null);
    onMounted(() => {
      // 获取节点
      const myChart = echarts.init(
        document.getElementById("histogramBar") as HTMLElement
      );
      myChart.setOption({
        tooltip: {
            backgroundColor: "rgba(0,0,0,0.5)", // 提示框浮层的背景颜色
            borderColor: "transparent",
          trigger: "axis",
          axisPointer: {
            type: "none", // 默认为直线，可选为：'line' | 'shadow'
          },
          textStyle: {
            align: "left",
            lineHeight: 26,
            color:'#fff'
          },
        },
        grid: {
          left: "3%",
          right: "8%",
          bottom: "10%",
          top: "10%",
          containLabel: true,
        },
        xAxis: {
          type: "category",
          data: ["2020", "2021", "2022", "2023", "2024", "2025"],
          axisLabel: {
            color: "#01D4F9",
            show: true,
            interval: 0,
            align: "center",
          },
          axisLine: {
            lineStyle: {
              color: "#01D4F9",
            },
          },
        },
        yAxis: {
          type: "value",
          axisLabel: {
            color: "#01D4F9",
          },
          nameGap: "20",
          splitLine: {
            show: true,
            lineStyle: {
              color: ["#01D4F9"],
              width: 1,
              type: "dotted",
            },
          },
          axisLine: {
            show: false,
            lineStyle: {
              color: "#D9DADA",
            },
          },
        },
        series: [
          {
            name: "采集",
            type: "bar",
            stack: "总量",

            barWidth: 12,
            itemStyle: {
              normal: {
                color: "#1A60FF",
                barBorderRadius: [6, 6, 0, 0],
              },
            },
            label: {
              normal: {
                color: "#CAA151",
                show: false,
                offset: [0, 1],
                // top / left / right / bottom / inside / insideLeft / insideRight / insideTop / insideBottom / insideTopLeft / insideBottomLeft / insideTopRight / insideBottomRight
                position: "insideRight",
                fontSize: "10",
                // position: "right ",
              },
            },
            z: 10,
            data: [20, 40, 60, 80, 100,200],
          },
        ],
      });
      window.addEventListener(
        "resize",
        debounce(() => {
          myChart.resize();
        })
      );
    });
    return {
      charts,
    };
  },
});
</script>
